<template>
  <el-dialog v-model="visible" title="400语音" width="500" :destroy-on-close="true">
    <p class="font-bold mb-[10px]">楼盘电话: {{ props.row.sell_phone }}</p>
    <p>是否同步：{{ model.audit === 1 ? "未同步" : "已同步" }}</p>
    <p>
      转接策略：{{
        !model.phone_conf.transType
          ? "随机"
          : model.phone_conf.transType === "ord"
          ? "顺振"
          : model.phone_conf.transType === "seq"
          ? "顺序"
          : "随机"
      }}
    </p>
    <p>目的码：{{ model.phone_conf.tel }}</p>
    <p>被叫语音：{{ model.phone_conf.aniVoiceName }}</p>
    <p class="mb-[15px]">主叫语音：{{ model.phone_conf.dniVoiceName }}</p>
    <el-form :model="model">
      <div class="">
        <p class="font-bold mb-[10px]">
          主叫语音<el-tag class="ml-[11px]" :type="shenheList(model.ani_audio.auditStatus).type">{{
            shenheList(model.ani_audio.auditStatus).label
          }}</el-tag>
        </p>
        <el-form-item label="语音内容" prop="model.ani_audio.content">
          <el-input type="textarea" v-model="model.ani_audio.content"></el-input>
        </el-form-item>
      </div>
      <div class="">
        <p class="font-bold mb-[10px]">
          被叫语音<el-tag class="ml-[11px]" :type="shenheList(model.dni_audio.auditStatus).type">{{
            shenheList(model.dni_audio.auditStatus).label
          }}</el-tag>
        </p>
        <el-form-item label="语音内容" prop="model.dni_audio.content">
          <el-input type="textarea" v-model="model.dni_audio.content"></el-input>
        </el-form-item>
      </div>
    </el-form>
    <template #footer>
      <el-button @click="updateLouAudio" v-auth="'同步楼盘语音'">同步楼盘语音</el-button>
      <el-button
        v-auth="'修改语音'"
        @click="add"
        type="primary"
        :disabled="model.ani_audio.auditStatus === 1 && model.dni_audio.auditStatus === 1"
        >修改</el-button
      >
    </template>
  </el-dialog>
</template>

<script setup lang="ts">
import { reactive, ref } from "vue";
import { getCheckPhone, addPhoneAudio, updateAwaitAudio } from "@/api/modules/loupan";
import { ElMessage } from "element-plus";
interface PhoneConf {
  dn: string;
  tel: string;
  aniVoiceName: string;
  dniVoiceName: string;
  transType: "ord" | "rnd" | "seq" | "";
}
const shenheList = (status: number): { label: string; type: any } => {
  if (status === 1) {
    return { label: "未审核", type: "warning" };
  } else if (status === 2) {
    return { label: "审核中", type: "default" };
  } else if (status === 3) {
    return { label: "审核失败", type: "info" };
  } else {
    return { label: "审核通过", type: "success" };
  }
};
interface Props {
  row: any;
  getTable?: () => Promise<any>;
}
interface Audio {
  audioComment: string;
  auditStatus: number;
  content: string;
  name: string;
  voiceUrl: string;
}
interface Model {
  audit: number;
  ani_audio: Audio;
  dni_audio: Audio;
  phone_conf: PhoneConf;
}
const model = reactive<Model>({
  audit: 1,
  ani_audio: {
    audioComment: "",
    auditStatus: 1,
    content: "",
    name: "",
    voiceUrl: ""
  },
  dni_audio: {
    audioComment: "",
    auditStatus: 1,
    content: "",
    name: "",
    voiceUrl: ""
  },
  phone_conf: {
    dn: "",
    tel: "",
    aniVoiceName: "",
    dniVoiceName: "",
    transType: ""
  }
});

const initData = reactive({});
const props = ref<Props>({
  row: JSON.parse(JSON.stringify(initData))
});

const visible = ref(false);

// 获取语音
const getPhoneApi = async () => {
  try {
    const { data } = await getCheckPhone({ lou_id: props.value.row.id });
    model.ani_audio = (data as any).ani_audio;
    model.dni_audio = (data as any).dni_audio;
    model.phone_conf = (data as any).phone_conf;
  } catch (error) {
    console.log(error);
  }
};

const acceptParams = (params: Props) => {
  props.value = params;
  visible.value = true;
  console.log(params);
  getPhoneApi();
};
// 添加或者修改语音
const add = async () => {
  try {
    await addPhoneAudio(props.value.row.id, model);
    ElMessage.success("成功");
    model.ani_audio.auditStatus = 1;
    model.dni_audio.auditStatus = 1;
  } catch (error) {}
};
const updateLouAudio = async () => {
  try {
    await updateAwaitAudio(model.phone_conf.dn);
    ElMessage.success("成功");
    model.audit = 2;
  } catch (error) {}
};
defineExpose({ acceptParams });
</script>

<style></style>
